package com.zw.mes.module.tecdrawsign.controller;


import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zw.mes.base.BaseController;
import com.zw.mes.common.JsonResult;
import com.zw.mes.entity.technology.DrawSign;
import com.zw.mes.module.cost.model.DictCommon;
import com.zw.mes.module.cost.service.DictCommonService;
import com.zw.mes.module.tecdrawsign.service.DrawSignService;
import com.zw.mes.module.tecdrawsign.model.DictEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zw.mes.constant.Constant.GROUP_SPECTYPE;
import static com.zw.mes.constant.Constant.GROUP_WORKSHOP;

/**
 * @author mayongfeng
 * @version 1.0.0
 * @ClassName PurchasedController.java
 * @Description TODO
 * @createTime 2021年01月29日 09:06:00
 */
@Controller
@RequestMapping("/tecdrawsign")
@SuppressWarnings("all")
public class DrawSignController extends BaseController {

    @Autowired
    private DictCommonService dictCommonService;
    @Autowired
    private DrawSignService drawSignService;


/****************************************************图纸签收***********************************************************/
    /**
     * @Author mayongfeng
     * @Date 14:15 2021/1/29
     * @Description 页面跳转到生产运营部图纸签收记录
     *
     **/
    @GetMapping
    public String signList(Model model){
        model.addAttribute("special", dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        model.addAttribute("workshop", dictCommonService.findDictByGroupName(GROUP_WORKSHOP));
        return "technology/sign/drawLssue";
    }

    /**
     * @Author mayongfeng
     * @Date 10:52 2020/11/26
     * @Description 查询生产运营部所有的图纸变更记录
     *
     **/
    @ResponseBody
    @PostMapping("/list")
    public JsonResult getAll(DrawSign drawSign){
        startPage();
        List<DrawSign> drawChaRecords = drawSignService.getAll(drawSign);
        return jsonResult(drawChaRecords);
    }

 /**
     * @Author mayongfeng
     * @Date 10:52 2020/11/26
     * @Description 查询分配的生产厂
     *
     **/
    @ResponseBody
    @PostMapping("/workshop")
    public JsonResult workshop(DrawSign drawSign){
        List<DictCommon> list = dictCommonService.findDictByGroupName(GROUP_WORKSHOP);
        return jsonResult(list);
    }


/**************************************************图纸变更签收*********************************************************/
    /**
     * @Author mayongfeng
     * @Date 14:15 2021/1/29
     * @Description 页面跳转到生产运营部的图纸变更签收记录
     *
     **/
    @GetMapping("changSign")
    public String changSign(Model model){
        model.addAttribute("special", dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        return "technology/sign/drawChaLssue";
    }

    /**
     * @Author mayongfeng
     * @Date 10:52 2020/11/26
     * @Description 查询生产运营部的所有图纸变更记录
     *
     **/
    @ResponseBody
    @PostMapping("cha/list")
    public JsonResult getChaAll(DrawSign drawSign){
        startPage();
        List<DrawSign> drawDistrRecords = drawSignService.getChaAll(drawSign);
        return jsonResult(drawDistrRecords);
    }
/**************************************************公共调用方法**********************************************************/
 /**
     * @Author mayongfeng
     * @Date 10:52 2020/11/26
     * @Description 将图纸记录分发到生产厂
     *
     **/
    @ResponseBody
    @PostMapping("submitCJ")
    public JsonResult submitCJ (Integer lssueId,String works,Integer changeType){
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm").create();
        List<DictEnum> dictEnumList = gson.fromJson(works, new TypeToken<List<DictEnum>>() {}.getType());
        int i = drawSignService.submitCj(dictEnumList,lssueId,changeType);
        return jsonResult(i);
    }

    /**
     * @Author mayongfeng
     * @Date 10:52 2020/11/26
     * @Description 生产运营部签收
     *
     **/
    @ResponseBody
    @PostMapping("prodSign")
    public JsonResult prodSign (Integer id,Integer type){
        int i = drawSignService.updateProdSign(id,type);
        return jsonResult(i);
    }

    /**
     * @Author mayongfeng
     * @Date 14:15 2021/1/29
     * @Description 页面跳转到生产厂的图纸变更签收记录
     *
     **/
    @GetMapping("tt")
    public String tt(Model model ,Integer id){
        model.addAttribute("special", dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        model.addAttribute("ttid", id);
        return "technology/sign/drawSelect";
    }

    /**
     * @Author mayongfeng
     * @Date 14:15 2021/1/29
     * @Description 页面跳转到生产厂的图纸变更签收记录
     *
     **/
    @GetMapping("chatt")
    public String chatt(Model model,Integer id){
        model.addAttribute("special", dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        model.addAttribute("chaid", id);
        return "technology/sign/drawChaSelect";
    }




}
